<template>
  <div id="noteffective">
    <div class="tables">
      <el-table
        :data="tableData"
        class="table"
        height="100%"
        ref="jdjgTable"
        @sort-change="sortChange"
        :header-cell-style="{
          padding: '0px',
          background: 'linear-gradient(0deg, #F4F6F9, #EAECF4, #F3F6F9)'
        }"
        :row-class-name="tabRowClassName"
        header-row-class-name="mapTable_th"
      >
        <el-table-column width="60" align="center" type="index" :index="addIndex" label="序号">
          <el-table-column width="60" align="center" type="index" label="检索"> </el-table-column>
        </el-table-column>
        <el-table-column label="合同编号" align="center">
          <el-table-column align="center" sortable="custom" prop="contractNo" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="招标内容" align="center">
          <el-table-column align="center" sortable="custom" prop="biddingContent" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="供应商名称" align="center">
          <el-table-column align="center" sortable="custom" prop="providerName" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-select v-model.trim="searchQrcoUsed" placeholder="请选择" @change="getDataChange">
                  <el-option label="全部" :value="null"></el-option>
                  <el-option label="已使用" :value="1"></el-option>
                  <el-option label="未使用" :value="2"></el-option>
                </el-select>
              </div>
            </template>
            <template slot-scope="scope">
              <el-button type="text" class="xg czBtn" size="small" @click="checkCompony(scope.row)">
                {{ scope.row.providerName }}
              </el-button>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="合同金额(元)" align="center">
          <el-table-column align="center" prop="contractAmount" width="150"> </el-table-column>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <el-table-column align="center" sortable="custom" prop="stateDescription" width="150">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
              </div>
            </template>
            <template slot-scope="scope">
              <div>
                {{ scope.row.stateDescription || '--' }}
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="中标时间" align="center">
          <el-table-column align="center" sortable="custom" prop="winningTime" width="180">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="撤销时间" align="center">
          <el-table-column align="center" sortable="custom" prop="revocationTime" width="180">
            <template slot="header" align="center" slot-scope="{}">
              <div class="searchBox" @click.stop>
                <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" align="center" width="160" fixed="right">
          <el-table-column align="center" width="160">
            <template slot-scope="scope">
              <div class="" v-if="scope.row.operate === 1">
                <el-button type="text" class="xg czBtn" size="small" @click="handleClick('编辑', scope.row)">
                  编辑
                </el-button>
                <el-button type="text" class="ty czBtn" size="small" @click="handleClick('删除', scope.row)">
                  删除
                </el-button>
              </div>
              <div class="" v-if="scope.row.operate === 2">
                <el-button type="text" class="ty czBtn" size="small" @click="handleClick('撤销', scope.row)">
                  撤销
                </el-button>
                <el-button type="text" class="xg czBtn" size="small" @click="handleClick('查看', scope.row)">
                  查看
                </el-button>
              </div>
              <div class="" v-if="scope.row.operate === 3">
                <el-button type="text" class="xg czBtn" size="small" @click="handleClick('查看', scope.row)">
                  查看
                </el-button>
              </div>
              <div class="" v-if="scope.row.operate === 4">
                <el-button type="text" class="xg czBtn" size="small" @click="handleClick('签订合同', scope.row)">
                  签订合同
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <div class="pags">
      <element-pagination @getData="getPagChange" :Total="total"> </element-pagination>
    </div>
  </div>
</template>

<script>
import ElementPagination from '../../../../components/ElementPagination.vue'
export default {
  data() {
    return {
      searchQrcoUsed: '',
      searchPositionName: '',
      tableData: [],
      total: 0,
      size: 15,
      page: 1
    }
  },
  components: { ElementPagination },
  mounted() {
    this.getData()
  },
  methods: {
    checkCompony(row) {
      const { bidCompanyId } = row
      if (bidCompanyId) {
        localStorage.setItem('supplierID', bidCompanyId)
        const { href } = this.$router.resolve({ name: 'SupplierDetail', query: { id: bidCompanyId } })

        window.open(href, '_blank')
      }
    },
    handleClick(val, scope) {
      if (val === '查看') {
        this.$emit('checkContract', '查看', scope)
      } else if (val === '编辑') {
        this.$emit('checkContract', '编辑', scope)
      } else if (val === '删除') {
        this.$confirm('是否删除该合同?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$https({
            method: 'post',
            url: '/contract/deleteContract',
            data: {
              id: scope.id
            }
          }).then(res => {
            if (res.code === 0) {
              this.getData()
              this.$message.success('删除成功')
            } else {
              this.$message.error(res.msg)
            }
          })
        })
      } else if (val === '审核') {
      } else if (val === '撤销') {
        this.$confirm('是否撤销审核?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$https({
            method: 'post',
            url: '/contract/revokeContract',
            data: {
              id: scope.id
            }
          })
            .then(res => {
              if (res.code === 0) {
                this.$message.success('撤销成功')
                this.getData()
              } else {
                this.$message.error(res.msg)
              }
            })
            .catch(err => {
              console.log(err)
            })
        })
      } else if (val === '签订合同') {
        this.$emit('checkContract', '签订合同', scope)
      }
    },
    getDataChange() {},
    getPagChange(data) {
      this.page = data.currentPage
      this.size = data.pagesize
      this.getData()
    },
    getData() {
      this.$https({
        method: 'post',
        url: '/contract/queryContractList',
        data: {
          page: this.page,
          size: this.size,
          state: 0
        }
      })
        .then(res => {
          if (res.code === 0) {
            this.total = res.data.total
            this.tableData = res.data.records
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.page - 1) * this.size
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  }
}
</script>
<style lang="less" scoped>
#noteffective {
  height: 100%;
  .tables {
    height: calc(100% - 62px);
  }
}
.xg {
  color: #166df1;
}
.ty {
  color: #ff3d3d;
}
</style>
